package com.txm.activityMQ;

import org.apache.activemq.command.ActiveMQObjectMessage;
import org.springframework.jms.support.converter.MessageConversionException;
import org.springframework.jms.support.converter.MessageConverter;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import java.io.Serializable;

/**
 * Created by tangxinmao on 2017/5/4.
 */
public class MQMessageConverter implements MessageConverter {

    public Message toMessage(Object o, Session session) throws JMSException, MessageConversionException {
        ActiveMQObjectMessage msg = (ActiveMQObjectMessage) session.createObjectMessage();
        msg.setObject((Serializable) o);
        return msg;

    }


    public Object fromMessage(Message message) throws JMSException, MessageConversionException {
        return ((ActiveMQObjectMessage) message).getObject();
    }
}
